
global ROOT ""
global data "$ROOT/Data"
global dofiles "$ROOT/DoFiles"
global tables "$ROOT/Tables"
global figures "$ROOT/Figures"

use "$data/baseline_data.dta", clear



*First, checking the sample balance based on the original cluster

/*Women's groups vs control */
count if treatment_o==2
count if treatment_o==4
qui {
foreach v of varlist h_member h_sroom h_electric h_radio h_cycle h_mbike h_car h_lamp h_oxcart/*
*/ h_worker married pri sec w_pri w_noedu wcba_w_age h_agri_wk dirt_floor roof_nat agri_own/*
*/ no_agri piped trad_pit bush chewa christian w_farmer student small_bus {
di "`v'"
	reg `v' wgonly_o, cluster(zone_o)
	scalar rdof=e(df_r)
	scalar tstat=_b[wgonly_o]/_se[wgonly_o]
	scalar pvalue=2*ttail(rdof,abs(tstat))
	gen beta=_b[wgonly_o]
	gen mean0=_b[_cons]
	gen se0=_se[_cons]
	gen se1=_se[wgonly_o]
	gen mean1=mean0+beta
	noi di as txt "`v'" "{col 22}" as res %6.3f  mean0 "{col 32}" as res %6.3f  mean1 "{col 42}" as res %6.3f  beta "{col 52}" as res %5.3f se1 "{col 62}" as res %5.3f pvalue
	drop beta mean* se0 se1
	
									}
}

* Wild bootstrap cluster t p-values
foreach v of varlist h_member h_sroom h_electric h_radio h_cycle h_mbike h_car h_lamp h_oxcart/*
*/ h_worker married pri sec w_pri w_noedu wcba_w_age h_agri_wk dirt_floor roof_nat agri_own/*
*/ no_agri piped trad_pit bush chewa christian w_farmer student small_bus {
 di "`v'"
 qui reg `v' wgonly_o, cluster(zone_o)
boottest wgonly_o

}

	
/* Next, the sample we actually use */
preserve
use respid1 respid2 vill1 vill2 treatment_o wave using  "$data\analysisfinal.dta", clear
drop if treatment_o==1 | treatment_o==3
drop treatment_o
keep if wave==1
ren respid1 respid
so respid	
tempfile same
save `same'.dta, replace
restore

so respid
merge respid using `same'.dta
ta _merge

keep if _merge==3
duplicates drop respid respid2, force

keep if vill1==vill2
drop if vill1==.

* Actual sample used
count if treatment_o==2
count if treatment_o==4
qui {
foreach v of varlist h_member h_sroom h_electric h_radio h_cycle h_mbike h_car h_lamp h_oxcart/*
*/ h_worker married pri sec w_pri w_noedu wcba_w_age h_agri_wk dirt_floor roof_nat agri_own/*
*/ no_agri piped trad_pit bush chewa christian w_farmer student small_bus {
di "`v'"
	reg `v' wgonly_o, cluster(zone_o)
	scalar rdof=e(df_r)
	scalar tstat=_b[wgonly_o]/_se[wgonly_o]
	scalar pvalue=2*ttail(rdof,abs(tstat))
	gen beta=_b[wgonly_o]
	gen mean0=_b[_cons]
	gen se0=_se[_cons]
	gen se1=_se[wgonly_o]
	gen mean1=mean0+beta
	noi di as txt "`v'" "{col 22}" as res %6.3f  mean0 "{col 32}" as res %6.3f  mean1 "{col 42}" as res %6.3f  beta "{col 52}" as res %5.3f se1 "{col 62}" as res %5.3f pvalue
	drop beta mean* se0 se1
	
									}
}

* Wild bootstrap cluster t p-values
foreach v of varlist h_member h_sroom h_electric h_radio h_cycle h_mbike h_car h_lamp h_oxcart/*
*/ h_worker married pri sec w_pri w_noedu wcba_w_age h_agri_wk dirt_floor roof_nat agri_own/*
*/ no_agri piped trad_pit bush chewa christian w_farmer student small_bus {
 di "`v'"
 qui reg `v' wgonly_o, cluster(zone_o)
	boottest wgonly_o

}
	
	

